﻿<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
    <meta name="Author" content="">
    <meta content="" name="design">
    <title>新闻列表</title>
    <link rel="stylesheet" href="../css/base.css"/>
    <script type="text/javascript" src="../js/jquery-1.9.1.min.js"></script>
    <!--[if lt IE 9]>
    <script type="text/javascript" src="../js/html5shiv.v3.72.min.js"></script>
    <![endif]-->
</head>
<body>
    <div class="news_list">
        <h1>新闻列表</h1>
        <table cellpadding="0" cellspacing="0" width="100%" id="newsListTable">
            <thead>
                <tr>
                    <th>ID</th>
                    <th>标题</th>
                    <th>图片</th>
                    <th>简述</th>
                    <th>推荐</th>
                    <th>日期</th>
                    <th>管理</th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td>推荐｜删除｜编辑</td>
                </tr>
                <tr>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td>推荐｜删除｜编辑</td>
                </tr>
                <tr>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td>推荐｜删除｜编辑</td>
                </tr>
            </tbody>
        </table>
       <div class="check">
           <input type="checkbox" id="checkAll"/><label for="checkAll">全选</label>
       </div>
        <a href="#" class="delete">批量删除</a>
        <div class="pagination clear">
            <a href="#">首页</a>
            <a href="">上一页</a>
            <div class="num">
                <a href="#">1</a>
                <a href="#">2</a>
                <a href="#">3</a>
                <a href="#">4</a>
                <a href="#">5</a>
                <a href="#">6</a>
            </div>
            <span>...</span>
            <a href="#">下一页</a>
        </div>




    </div>

<script type="text/javascript">
    //整站无图处理
    jQuery.each(jQuery("img"), function (i, n) {
        jQuery(n).error(function () {
            n.src = 'images/nopic.jpg';
        });
        n.src = n.src;
    });
</script>
<script type="text/javascript">
$(function() {
    newsPageList({}, 1, 10);
});

function newsPageList(news, page, size) {
    $.ajax({
        url:'/news/page.do?page=' + page + '&size='+size,
        type:'post',
        data: news,
        success:function(result) {
            console.log(result);
            if (result && result.datas && result.datas.length > 0) {
                renderListTable(result.datas);
            }
        },
        error:function() {
            alert('系统错误');
        }
    });
}

function renderListTable(data) {
    $("#newsListTable tbody").html('');
    var html = "";
    data.forEach(function(item, index, array) {
        html += "<tr><td>"+item.id+"</td><td>"+item.title+"</td><td><img style='width:50px;height:50px;' src='"+item.imgUrl+"'/></td><td>"+item.sketch+"</td><td>"+(item.behavior == '1'?'是':'否')+"</td><td>"+item.createTime+"</td><td>推荐｜删除｜编辑</td></tr>";
    });
    $("#newsListTable tbody").html(html);
}
</script>
</body>
</html>

